﻿using Config;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using UI.TestModule;
using System.IO;
using Communication.Model.speedData;
using Communication.Model.netPacket;
using Communication.Model.packetType;
using Communication.Model.displacement;
using Communication.Model.acceleration;
using Communication.Model.configuration;
using Communication.Model.slowSignal;
using Communication.TcpIpService;
using Communication.Model.speedRealTVol;
using Communication.Interface;
using UI.Models;
using System.Threading;

namespace UI
{
<<<<<<< HEAD
    public partial class MainForm : Form
    {
        private void SetControlText(Control ctrl, string name)
        {
            if (ctrl.IsHandleCreated && ctrl.InvokeRequired)
            {
                ctrl.Invoke(new Action<Control, string>(SetControlText), ctrl, name);
                return;
            }
            ctrl.Text = name;
        }
=======
    //更新界面处理逻辑函数
    public partial class MainForm : Form
    {
        private int DisplacementNo = 0;
        private int AccNo = 0;


>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void SetGeneral()
        {
            for (int i = 0; i < 32; i++)
            {
                Control ctrl = tableLayoutPanel1.Controls[i];
                int type = settings.ChannelConfig.Omaplchannels.Channels[i].SensorType;
                //ctrl.Text = i.ToString();
                if (type == 0)
                {
                    string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName + "\r\n";
                    //name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                    SetControlText(ctrl, name);
                }
                else
                {
                    string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName + "\r\n";
                    //name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                    SetControlText(ctrl, name);
                }
            }
            for (int i = 0; i < 6; i++)
            {
                Control ctrl = tableLayoutPanel1.Controls[i + 32];
                string name = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].ChannelName + "\r\n";
                //name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                SetControlText(ctrl, name);
            }
        }
        private void SetChartForm()
        {
            comboBox1.Items.Clear();
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                comboBox1.Items.Add(name);
            }
            comboBox1.SelectedIndex = 0;
            //chart1.ChartAreas.Clear();
        }
<<<<<<< HEAD
=======

        //加载转速通道配置列表到下拉菜单
        private void SetRotateForm()
        {
            comboBox2.Items.Clear();
            int count = settings.ChannelConfig.omplconfig_rotationchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].ChannelName;
                comboBox2.Items.Add(name);
            }
            comboBox2.SelectedIndex = 0;
        }
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void SetOctaveForm()
        {
            cb_octave.Items.Clear();
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                if (settings.ChannelConfig.Omaplchannels.Channels[i].SensorType == 2)
                {
                    string id = settings.ChannelConfig.Omaplchannels.Channels[i].No.ToString();
                    string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                    cb_octave.Items.Add(id + ":" + name);
                }
            }
            cb_octave.SelectedIndex = 0;
<<<<<<< HEAD

        }
        private void SetRpmTimeWave()
        {
            rpm_timewave.Items.Clear();
            int count = settings.ChannelConfig.omplconfig_rotationchannels.Channels.Count;
           // MessageBox.Show(count.ToString());
            for (int i = 0; i < count; i++)
            {
               
                    string id = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].No.ToString();
                    string name = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].ChannelName;
                    rpm_timewave.Items.Add(id + ":" + name);
                
            }
            rpm_timewave.SelectedIndex = 0;
        }
        private void SetConfigForm()
        {
            //振动通道配置
            listBox1.Items.Clear();
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                listBox1.Items.Add(name);
            }
            listBox1.SelectedIndex = 0;

            //转速通道配置
            listBox2.Items.Clear();
            count = settings.ChannelConfig.omplconfig_rotationchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].ChannelName;
                listBox2.Items.Add(name);
            }
            listBox2.SelectedIndex = 0;

            InitialTestPoints();
            InitialStorageInfo();

        }
        private void SetDataGridForm()
        {
            if (DisplacementNo != 0)
            {
                //初始化位移列表
                dataGridView1.Columns.Add("id", "通道ID");
                dataGridView1.Columns.Add("name", "通道名称");
                dataGridView1.Columns.Add("rpm", "转速");
                dataGridView1.Columns.Add("p2p", "峰峰值");
                dataGridView1.Columns.Add("gapvoltage", "间隙电压");
                dataGridView1.Columns.Add("rms", "平方根值");
                dataGridView1.Columns.Add("1xA", "一倍频幅值");
                dataGridView1.Columns.Add("1xP", "一倍频相位");
                dataGridView1.Columns.Add("2xA", "二倍频幅值");
                dataGridView1.Columns.Add("2xP", "二倍频相位");
                dataGridView1.Columns.Add("halfxA", "半频幅值");
                dataGridView1.Columns.Add("halfxP", "半频相位");
                dataGridView1.Rows.Add(DisplacementNo);
            }
            if (AccNo != 0)
            {
                //初始化振动加速度列表
                dataGridView2.Columns.Add("id", "通道ID");
                dataGridView2.Columns.Add("name", "通道名称");
                dataGridView2.Columns.Add("rpm", "转速");
                dataGridView2.Columns.Add("TotalDB", "振动总值");
                dataGridView2.Columns.Add("highDB", "高频总值");
                dataGridView2.Columns.Add("lowDB", "低频总值");
                dataGridView2.Columns.Add("velocityRMS", "速度均方根值");
                dataGridView2.Columns.Add("AverageVol", "平均电压");
                dataGridView2.Columns.Add("displacementRMS", "位移均方根值");
                dataGridView2.Columns.Add("1xA", "一倍频幅值");
                dataGridView2.Columns.Add("2xA", "二倍频幅值");
                dataGridView2.Columns.Add("3xA", "三倍频幅值");
                dataGridView2.Rows.Add(AccNo);
            }
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                int No = settings.ChannelConfig.Omaplchannels.Channels[i].No;
                string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                if (i < DisplacementNo)
                {
                    dataGridView1.Rows[i].Cells["id"].Value = No.ToString();
                    dataGridView1.Rows[i].Cells["name"].Value = name;
                }
                if (i >= (32 - AccNo))
                {
                    dataGridView2.Rows[i - DisplacementNo].Cells["id"].Value = No.ToString();
                    dataGridView2.Rows[i - DisplacementNo].Cells["name"].Value = name;
                }

            }
        }
        private void SetSelectecIndexOfListBox()
        {
            if (_listBox != null)
            {
                _listBox.SelectedIndex = _selectedIndex;
            }
        }
        //统计通道数量
        private void GetChTypeNo()
        {
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                int type = settings.ChannelConfig.Omaplchannels.Channels[i].SensorType;
                if (type == 0)
                {
                    DisplacementNo++;//获取位移通道数量
                    //MessageBox.Show("位移");
                }
                if (type == 2)
                {
                    AccNo++;//获取加速度通道数量
                            // MessageBox.Show("加速度");
                }
            }
        }
        //统计报警使能设置信息
        public void Getenablesetting()
        {
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            for (int i = 0; i < 32; i++)
            {
                enablesetting[i, 0] = settings.ChannelConfig.Omaplchannels.Channels[i].AccHighAmplitudeValueIsUser;
                enablesetting[i, 1] = settings.ChannelConfig.Omaplchannels.Channels[i].AccLowAmplitudeValueIsUser;
                enablesetting[i, 2] = settings.ChannelConfig.Omaplchannels.Channels[i].AccTotalAmplitudeValueIsUser;
                enablesetting[i, 3] = settings.ChannelConfig.Omaplchannels.Channels[i].FlagIsUser;

                enablesetting[i, 4] = settings.ChannelConfig.Omaplchannels.Channels[i].Enable;
                enablesetting[i, 5] = settings.ChannelConfig.Omaplchannels.Channels[i].Frequency1Enable;
                enablesetting[i, 6] = settings.ChannelConfig.Omaplchannels.Channels[i].Frequency2Enable;
                enablesetting[i, 7] = settings.ChannelConfig.Omaplchannels.Channels[i].FrequencyHalfEnable;
                //   MessageBox.Show(enablesetting[i, 0].ToString());


            }
        }
        //统计报警数值设置信息
        public void GetAlarmValue()
        {
            for (int i = 0; i < 32; i++)
            {
                alarmvalue[i, 0] = settings.ChannelConfig.Omaplchannels.Channels[i].AccHighAmplitudeYellowValue;
                alarmvalue[i, 1] = settings.ChannelConfig.Omaplchannels.Channels[i].AccHighAmplitudeRedValue;
                alarmvalue[i, 2] = settings.ChannelConfig.Omaplchannels.Channels[i].AccLowAmplitudeYellowValue;
                alarmvalue[i, 3] = settings.ChannelConfig.Omaplchannels.Channels[i].AccLowAmplitudeRedValue;
                alarmvalue[i, 4] = settings.ChannelConfig.Omaplchannels.Channels[i].AccTotalAmplitudeYellowValue;
                alarmvalue[i, 5] = settings.ChannelConfig.Omaplchannels.Channels[i].AccTotalAmplitudeRedValue;
                alarmvalue[i, 6] = 1;
                alarmvalue[i, 7] = 2;

                alarmvalue[i, 8] = settings.ChannelConfig.Omaplchannels.Channels[i].Warning;
                alarmvalue[i, 9] = settings.ChannelConfig.Omaplchannels.Channels[i].Alarm;
                alarmvalue[i, 10] = settings.ChannelConfig.Omaplchannels.Channels[i].Frequency1Warning;
                alarmvalue[i, 11] = settings.ChannelConfig.Omaplchannels.Channels[i].Frequency1Alarm;
                alarmvalue[i, 12] = settings.ChannelConfig.Omaplchannels.Channels[i].Frequency2Warning;
                alarmvalue[i, 13] = settings.ChannelConfig.Omaplchannels.Channels[i].Frequency2Alarm;
                alarmvalue[i, 14] = settings.ChannelConfig.Omaplchannels.Channels[i].FrequencyHalfWarning;
                alarmvalue[i, 15] = settings.ChannelConfig.Omaplchannels.Channels[i].FrequencyHalfAlarm;
                //MessageBox.Show(alarmvalue[i, 15].ToString());
            }
        }
        //获取批量修改配置
        public void GetBatchedChannel()
        {
            for (int i = 0; i < 32; i++)
            {
                batched[i] = settings.ChannelConfig.Omaplchannels.Channels[i].batched;
            }
        }
        private void SaveSettings()
        {
            try
            {
                #region 【更新振动通道配置内容】
                //--基本信息
                int id = listBox1.SelectedIndex;
                settings.ChannelConfig.Omaplchannels.Channels[id].ChannelName = tb_name.Text;
                settings.ChannelConfig.Omaplchannels.Channels[id].FixAngle = float.Parse(tb_angle.Text);
                settings.ChannelConfig.Omaplchannels.Channels[id].SpeedNo = cb_rpm.SelectedIndex + 1;
                //--传感器信息
                settings.ChannelConfig.Omaplchannels.Channels[id].SensorType = cb_sensorType.SelectedIndex;
                settings.ChannelConfig.Omaplchannels.Channels[id].Sensitivity = float.Parse(tb_sensitivity.Text);
                settings.ChannelConfig.Omaplchannels.Channels[id].PianYiLiang = float.Parse(tb_offset.Text);
                //--报警信息
                int type = cb_sensorType.SelectedIndex;
                if (type == 0)//位移通道报警信息设置
                {
                    //更新数据
                    settings.ChannelConfig.Omaplchannels.Channels[id].Warning = float.Parse(tb_all_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].Alarm = float.Parse(tb_all_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].Enable = enable_all.Checked ? 1 : 0;

                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Warning = float.Parse(tb_1x_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Alarm = float.Parse(tb_1x_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Enable = enable_1x.Checked ? 1 : 0;

                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Warning = float.Parse(tb_2x_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Alarm = float.Parse(tb_2x_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Enable = enable_2x.Checked ? 1 : 0;

                    settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfWarning = float.Parse(tb_half_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfAlarm = float.Parse(tb_half_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfEnable = enable_half.Checked ? 1 : 0;
                }
                else//保存加速度通道报警信息设置
                {
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeYellowValue = float.Parse(tb_total_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeRedValue = float.Parse(tb_total_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeValueIsUser = enable_total.Checked ? 1 : 0;

                    settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeYellowValue = float.Parse(tb_low_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeRedValue = float.Parse(tb_low_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeValueIsUser = enable_low.Checked ? 1 : 0;

                    settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeYellowValue = float.Parse(tb_high_warning.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeRedValue = float.Parse(tb_high_alarm.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeValueIsUser = enable_high.Checked ? 1 : 0;
                    //保存加速度标志位报警
                    settings.ChannelConfig.Omaplchannels.Channels[id].FlagIsUser = enable_alarm.Checked ? 1 : 0;
                }

                #endregion
                //更新转速通道配置文件

                id = listBox2.SelectedIndex;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChannelName = tb_rpm_name.Text;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].rationdir = cb_rpm_direction.SelectedIndex;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].JianXiangCaoVolCompare = float.Parse(tb_key_voltage.Text);
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPanNum = int.Parse(tb_gear_num.Text);
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPanCompareVol = float.Parse(tb_gear_voltage.Text);
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].JianXiangCao = rb_key_manual.Checked ? 1 : 0;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].JianXiangCaoAuto = rb_key_auto.Checked ? 1 : 0;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPan = rb_gear_manual.Checked ? 1 : 0;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPanAuto = rb_gear_auto.Checked ? 1 : 0;
                settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].VirtualSpeed = float.Parse(tb_rpm_virtual.Text);
               
                //统计报警使能信息
                //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
                Getenablesetting();
                //统计报警值设定信息
                GetAlarmValue();
                //更新采样设置
                SaveOmaplchannelsSet();
                //更新系统配置
                SaveSystemSet();
                //更新测点配置
                SaveTestPointSet();
                //更新存储配置
                SaveStorageSet();
                //保存文件
                settings.saveXml(settings.Path);
                //更新各个图
                SetGeneral();
                SetChartForm();
                SetConfigForm();
                SetDataGridForm();
                SetOctaveForm();

                SetSelectecIndexOfListBox();
                //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
                Getenablesetting();
                //统计报警值设定信息
                GetAlarmValue();
            }
            catch (Exception ex)
            { }
        }
        private void SaveBatchedSet()
        {
            settings.ChannelConfig.Omaplchannels.Channels[0].batched = checkBox1.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[1].batched = checkBox2.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[2].batched = checkBox3.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[3].batched = checkBox4.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[4].batched = checkBox5.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[5].batched = checkBox6.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[6].batched = checkBox7.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[7].batched = checkBox8.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[8].batched = checkBox9.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[9].batched = checkBox10.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[10].batched = checkBox11.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[11].batched = checkBox12.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[12].batched = checkBox13.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[13].batched = checkBox14.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[14].batched = checkBox15.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[15].batched = checkBox16.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[16].batched = checkBox17.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[17].batched = checkBox18.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[18].batched = checkBox19.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[19].batched = checkBox20.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[20].batched = checkBox21.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[21].batched = checkBox22.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[22].batched = checkBox23.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[23].batched = checkBox24.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[24].batched = checkBox25.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[25].batched = checkBox26.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[26].batched = checkBox27.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[27].batched = checkBox28.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[28].batched = checkBox29.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[29].batched = checkBox30.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[30].batched = checkBox31.Checked ? 1 : 0;
            settings.ChannelConfig.Omaplchannels.Channels[31].batched = checkBox32.Checked ? 1 : 0;
            
        }
        private void SaveSystemSet()
        {
            settings.SystemSet.IP = tb_IP.Text;
            settings.SystemSet.Port = int.Parse(tb_Port.Text);
            settings.SystemSet.IP1 = int.Parse(tb_strIP1.Text);
            settings.SystemSet.IP2 = int.Parse(tb_strIP2.Text);
            settings.SystemSet.IP3 = int.Parse(tb_strIP3.Text);
            settings.SystemSet.IP4 = int.Parse(tb_strIP4.Text);
            settings.SystemSet.nRefreshIndex = int.Parse(tb_nRefreshIndex.Text);
            settings.SystemSet.nSampleMode = cb_nSampleMode.Checked ? 1 : 0;
        }
        private void SaveTestPointSet()
        {
            int id = listBox3.SelectedIndex;
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].TestPointName = tb_tp_name.Text;
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelxindex = cb_tp_channelxindex.SelectedIndex;
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelyindex = cb_tp_channelxindey.SelectedIndex;
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelvola = int.Parse(tb_tp_channelvola.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelvolb = int.Parse(tb_tp_channelvolb.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearhousx = int.Parse(tb_tp_bearhousx.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearhousy = int.Parse(tb_tp_bearhousy.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].iniaxlex = int.Parse(tb_tp_iniaxlex.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].iniaxley = int.Parse(tb_tp_iniaxley.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearhori = int.Parse(tb_tp_bearhori.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearveri = int.Parse(tb_tp_bearveri.Text);
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].setiniposflag = cb_tp_setiniposflag.Checked ? 1 : 0;
            settings.ChannelConfig.omplconfig_testpos.TestPoints[id].saveiniposflag = cb_tp_saveiniposflag.Checked ? 1 : 0;
        }
        private void SaveOmaplchannelsSet()
        {
            int index = listBox1.SelectedIndex;
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin1Name = tb_tp_strOptionPin1Name.Text;
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin1UpThreshold = float.Parse(tb_tp_strOptionPin1UpThreshold.Text);
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin1DownThreshold = float.Parse(tb_tp_strOptionPin1DownThreshold.Text);
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin2Name = tb_tp_strOptionPin2Name.Text;
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin2UpThreshold = float.Parse(tb_tp_strOptionPin2UpThreshold.Text);
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin2DownThreshold = float.Parse(tb_tp_strOptionPin2DownThreshold.Text);
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin3Name = tb_tp_strOptionPin3Name.Text;
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin3UpThreshold = float.Parse(tb_tp_strOptionPin3UpThreshold.Text);
            settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin3DownThreshold = float.Parse(tb_tp_strOptionPin3DownThreshold.Text);
        }
        private void SaveStorageSet()
        {
            settings.StoreSet.HourInterval = cb_tp_nIndexHour.SelectedIndex;
            settings.StoreSet.DayInterval = cb_tp_nIndexDay.SelectedIndex;
            settings.StoreSet.WeekInterval = cb_tp_nIndexWeek.SelectedIndex;
            settings.StoreSet.MonthInterval = cb_tp_nIndexMonth.SelectedIndex;
            settings.StoreSet.YearInterval = cb_tp_nIndexYear.SelectedIndex;
            settings.StoreSet.LoadDB = int.Parse(tb_tp_strShengJiangSuBeg.Text);
            settings.StoreSet.StartSpeed = int.Parse(tb_tp_strShengJiangSuEnd.Text);
            settings.StoreSet.Store = cb_tp_nIndexVariableloadDB.SelectedIndex;
            settings.StoreSet.BlackBoxSavFre = int.Parse(tb_tp_STRHeiXiaZiBeforeEvent.Text);
            settings.StoreSet.BlackboxBeforeEvent = int.Parse(tb_tp_strHeiXiaZiAfterEvent.Text);
        }
        private void InitialStorageInfo()
        {
            omplconfig_store storeSet = settings.StoreSet;
            UpdateStorage();
        }
        private void UpdateStorage()
        {
            cb_tp_nIndexHour.SelectedIndex = settings.StoreSet.HourInterval;
            cb_tp_nIndexDay.SelectedIndex = settings.StoreSet.DayInterval;
            cb_tp_nIndexWeek.SelectedIndex = settings.StoreSet.WeekInterval;
            cb_tp_nIndexMonth.SelectedIndex = settings.StoreSet.MonthInterval;
            cb_tp_nIndexYear.SelectedIndex = settings.StoreSet.YearInterval;
            tb_tp_strShengJiangSuBeg.Text = settings.StoreSet.LoadDB.ToString();
            tb_tp_strShengJiangSuEnd.Text = settings.StoreSet.StartSpeed.ToString();
            cb_tp_nIndexVariableloadDB.SelectedIndex = settings.StoreSet.Store;
            tb_tp_STRHeiXiaZiBeforeEvent.Text = settings.StoreSet.BlackBoxSavFre.ToString();
            tb_tp_strHeiXiaZiAfterEvent.Text = settings.StoreSet.BlackboxBeforeEvent.ToString();

        }
        //变更选择通道时加载选择该通道的报警信息
=======
        }
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void UpdateConfigForm()
        {
            this.Invoke((EventHandler)delegate
            {
                //更新振动通道配置信息
                #region 通道信息
                int index = listBox1.SelectedIndex;
<<<<<<< HEAD
=======
                //MessageBox.Show("选中的通道索引是" + index);
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
                if (index >= 0)
                {
                    //基本信息
                    SetControlText(tb_id, settings.ChannelConfig.Omaplchannels.Channels[index].No.ToString());
                    SetControlText(tb_name, settings.ChannelConfig.Omaplchannels.Channels[index].ChannelName);
                    SetControlText(tb_angle, settings.ChannelConfig.Omaplchannels.Channels[index].FixAngle.ToString());
                    SetComboIndex(cb_rpm, settings.ChannelConfig.Omaplchannels.Channels[index].SpeedNo - 1);

                    //传感器信息
                    int type = settings.ChannelConfig.Omaplchannels.Channels[index].SensorType;
                    //SetControlText(textBox6, sensorType[type]);
                    SetComboIndex(cb_sensorType, settings.ChannelConfig.Omaplchannels.Channels[index].SensorType);
                    SetControlText(tb_sensitivity, settings.ChannelConfig.Omaplchannels.Channels[index].Sensitivity.ToString());
                    SetControlText(tb_offset, settings.ChannelConfig.Omaplchannels.Channels[index].PianYiLiang.ToString());

                    //报警信息
                    if (type == 0)//位移通道
                    {
                        //隐藏加速度通道配置内容
                        sc_alarm.Panel1.Hide();
                        sc_alarm.Panel2.Show();
<<<<<<< HEAD
                        //更新数据
                        tb_all_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Warning.ToString();
                        tb_all_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Alarm.ToString();
                        enable_all.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].Enable != 0 ? true : false;

                        tb_1x_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Warning.ToString();
                        tb_1x_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Alarm.ToString();
                        enable_1x.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Enable != 0 ? true : false;

                        tb_2x_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Warning.ToString();
                        tb_2x_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Alarm.ToString();
                        enable_2x.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Enable != 0 ? true : false;

                        tb_half_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfWarning.ToString();
                        tb_half_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfAlarm.ToString();
                        enable_half.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfEnable != 0 ? true : false;
                        
=======
                        //更新数据//
                        //通频阈值 预警值 报警值 使能
                        tb_all_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Warning.ToString();
                        tb_all_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Alarm.ToString();
                        enable_all.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].Enable != 0 ? true : false;
                        //1倍频阈值 预警值 报警值 使能
                        tb_1x_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Warning.ToString();
                        tb_1x_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Alarm.ToString();
                        enable_1x.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Enable != 0 ? true : false;
                        //2倍频阈值 预警值 报警值 使能
                        tb_2x_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Warning.ToString();
                        tb_2x_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Alarm.ToString();
                        enable_2x.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Enable != 0 ? true : false;
                        //0.5倍频阈值 预警值 报警值 使能
                        tb_half_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfWarning.ToString();
                        tb_half_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfAlarm.ToString();
                        enable_half.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfEnable != 0 ? true : false;
                       // MessageBox.Show(enable_half.Checked.ToString());

                       
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
                    }
                    else//加速度通道
                    {
                        //隐藏位移通道的报警设置内容
                        sc_alarm.Panel1.Show();
                        sc_alarm.Panel2.Hide();

                        //更新数据
<<<<<<< HEAD
                        tb_total_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeYellowValue.ToString();
                        tb_total_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeRedValue.ToString();
                        enable_total.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeValueIsUser != 0 ? true : false;

                        tb_low_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeYellowValue.ToString();
                        tb_low_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeRedValue.ToString();
                        enable_low.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeValueIsUser != 0 ? true : false;

                        tb_high_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeYellowValue.ToString();
                        tb_high_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeRedValue.ToString();
                        enable_high.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeValueIsUser != 0 ? true : false;
                        //读取配置文件的标志位报警参数
                        enable_alarm.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].FlagIsUser != 0 ? true : false;
                    
                    }
=======
                        //振动加速度总值 预警值 报警值 使能
                        tb_total_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeYellowValue.ToString();
                        tb_total_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeRedValue.ToString();
                        enable_total.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeValueIsUser != 0 ? true : false;
                        //低频段阈值 预警值 报警值 使能
                        tb_low_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeYellowValue.ToString();
                        tb_low_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeRedValue.ToString();
                        enable_low.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeValueIsUser != 0 ? true : false;
                        //高频段阈值 预警值 报警值 使能
                        tb_high_warning.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeYellowValue.ToString();
                        tb_high_alarm.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeRedValue.ToString();
                        enable_high.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeValueIsUser != 0 ? true : false;
                        //标志位保养使能
                        enable_flag.Checked = settings.ChannelConfig.Omaplchannels.Channels[index].FlagIsUser != 0 ? true : false;
                    }

>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
                }
                //更新采样设置
                if (index >= 0)
                {
                    tb_tp_strOptionPin1Name.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin1Name;
                    tb_tp_strOptionPin1UpThreshold.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin1UpThreshold.ToString();
                    tb_tp_strOptionPin1DownThreshold.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin1DownThreshold.ToString();
                    tb_tp_strOptionPin2Name.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin2Name;
                    tb_tp_strOptionPin2UpThreshold.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin2UpThreshold.ToString();
                    tb_tp_strOptionPin2DownThreshold.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin2DownThreshold.ToString();
                    tb_tp_strOptionPin3Name.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin3Name;
                    tb_tp_strOptionPin3UpThreshold.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin3UpThreshold.ToString();
                    tb_tp_strOptionPin3DownThreshold.Text = settings.ChannelConfig.Omaplchannels.Channels[index].OptionPin3DownThreshold.ToString();
                }

                //校正设置
                if (index >= 0)
                {
                    tb_tp_strAdjustFactor.Text = settings.ChannelConfig.Omaplchannels.Channels[index].AdjustFactor.ToString();
                    tb_tp_strZeroOffset.Text = settings.ChannelConfig.Omaplchannels.Channels[index].ZeroOffset.ToString();
                }
                #endregion
                //更新转速通道配置信息
                int id = listBox2.SelectedIndex;
                if (id >= 0)
                {
                    SetControlText(tb_rpm_name, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChannelName);
                    //SetControlText(tb_rpm_angle, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].an);
                    SetComboIndex(cb_rpm_direction, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].rationdir);
                    rb_key_manual.Checked = (settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].JianXiangCao == 1);
                    rb_key_auto.Checked = (settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].JianXiangCaoAuto == 1);
                    rb_gear_auto.Checked = (settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPanAuto == 1);
                    rb_gear_manual.Checked = (settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPan == 1);
                    SetControlText(tb_key_voltage, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].JianXiangCaoVolCompare.ToString());
                    SetControlText(tb_gear_num, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPanNum.ToString());
                    SetControlText(tb_gear_voltage, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].ChiLunPanCompareVol.ToString());
                    SetControlText(tb_rpm_virtual, settings.ChannelConfig.omplconfig_rotationchannels.Channels[id].VirtualSpeed.ToString());
                }
                //更新系统配置
                UpdateSysConfig();

                UpdateTestPoints();

                //更新存储设置
<<<<<<< HEAD
                //更新批量修改配置
                UpdateBatched();

            });

        }
        
        private void UpdateBatched()
        {
            
            
            checkBox1.Checked = settings.ChannelConfig.Omaplchannels.Channels[0].batched != 0 ? true : false;
            checkBox2.Checked = settings.ChannelConfig.Omaplchannels.Channels[1].batched != 0 ? true : false;
            checkBox3.Checked = settings.ChannelConfig.Omaplchannels.Channels[2].batched != 0 ? true : false;
            checkBox4.Checked = settings.ChannelConfig.Omaplchannels.Channels[3].batched != 0 ? true : false;
            checkBox5.Checked = settings.ChannelConfig.Omaplchannels.Channels[4].batched != 0 ? true : false;
            checkBox6.Checked = settings.ChannelConfig.Omaplchannels.Channels[5].batched != 0 ? true : false;
            checkBox7.Checked = settings.ChannelConfig.Omaplchannels.Channels[6].batched != 0 ? true : false;
            checkBox8.Checked = settings.ChannelConfig.Omaplchannels.Channels[7].batched != 0 ? true : false;
            checkBox9.Checked = settings.ChannelConfig.Omaplchannels.Channels[8].batched != 0 ? true : false;
            checkBox10.Checked = settings.ChannelConfig.Omaplchannels.Channels[9].batched != 0 ? true : false;
            checkBox11.Checked = settings.ChannelConfig.Omaplchannels.Channels[10].batched != 0 ? true : false;
            checkBox12.Checked = settings.ChannelConfig.Omaplchannels.Channels[11].batched != 0 ? true : false;
            checkBox13.Checked = settings.ChannelConfig.Omaplchannels.Channels[12].batched != 0 ? true : false;
            checkBox14.Checked = settings.ChannelConfig.Omaplchannels.Channels[13].batched != 0 ? true : false;
            checkBox15.Checked = settings.ChannelConfig.Omaplchannels.Channels[14].batched != 0 ? true : false;
            checkBox16.Checked = settings.ChannelConfig.Omaplchannels.Channels[15].batched != 0 ? true : false;
            checkBox17.Checked = settings.ChannelConfig.Omaplchannels.Channels[16].batched != 0 ? true : false;
            checkBox18.Checked = settings.ChannelConfig.Omaplchannels.Channels[17].batched != 0 ? true : false;
            checkBox19.Checked = settings.ChannelConfig.Omaplchannels.Channels[18].batched != 0 ? true : false;
            checkBox20.Checked = settings.ChannelConfig.Omaplchannels.Channels[19].batched != 0 ? true : false;
            checkBox21.Checked = settings.ChannelConfig.Omaplchannels.Channels[20].batched != 0 ? true : false;
            checkBox22.Checked = settings.ChannelConfig.Omaplchannels.Channels[21].batched != 0 ? true : false;
            checkBox23.Checked = settings.ChannelConfig.Omaplchannels.Channels[22].batched != 0 ? true : false;
            checkBox24.Checked = settings.ChannelConfig.Omaplchannels.Channels[23].batched != 0 ? true : false;
            checkBox25.Checked = settings.ChannelConfig.Omaplchannels.Channels[24].batched != 0 ? true : false;
            checkBox26.Checked = settings.ChannelConfig.Omaplchannels.Channels[25].batched != 0 ? true : false;
            checkBox27.Checked = settings.ChannelConfig.Omaplchannels.Channels[26].batched != 0 ? true : false;
            checkBox28.Checked = settings.ChannelConfig.Omaplchannels.Channels[27].batched != 0 ? true : false;
            checkBox29.Checked = settings.ChannelConfig.Omaplchannels.Channels[28].batched != 0 ? true : false;
            checkBox30.Checked = settings.ChannelConfig.Omaplchannels.Channels[29].batched != 0 ? true : false;
            checkBox31.Checked = settings.ChannelConfig.Omaplchannels.Channels[30].batched != 0 ? true : false;
            checkBox32.Checked = settings.ChannelConfig.Omaplchannels.Channels[31].batched != 0 ? true : false;

        }
=======

            });
        }
       //界面更新网络信息配置
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void UpdateSysConfig()
        {
            SetControlText(tb_IP, settings.SystemSet.IP);
            SetControlText(tb_Port, settings.SystemSet.Port.ToString());
            SetControlText(tb_strIP1, settings.SystemSet.IP1.ToString());
            SetControlText(tb_strIP2, settings.SystemSet.IP2.ToString());
            SetControlText(tb_strIP3, settings.SystemSet.IP3.ToString());
            SetControlText(tb_strIP4, settings.SystemSet.IP4.ToString());
            SetControlText(tb_nRefreshIndex, settings.SystemSet.nRefreshIndex.ToString());
            cb_nSampleMode.Checked = settings.SystemSet.nSampleMode != 0 ? true : false;
        }

        private void UpdateTestPoints()
        {
            int id = listBox3.SelectedIndex;
            if (id >= 0)
            {
                tb_tp_name.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].TestPointName;
                cb_tp_channelxindex.SelectedIndex = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelxindex;
                cb_tp_channelxindey.SelectedIndex = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelyindex;
                tb_tp_channelvola.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelvola.ToString();
                tb_tp_channelvolb.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].channelvolb.ToString();
                tb_tp_bearhousx.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearhousx.ToString();
                tb_tp_bearhousy.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearhousy.ToString();
                tb_tp_iniaxlex.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].iniaxlex.ToString();
                tb_tp_iniaxley.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].iniaxley.ToString();
                tb_tp_bearhori.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearhori.ToString();
                tb_tp_bearveri.Text = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].bearveri.ToString();
                cb_tp_setiniposflag.Checked = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].setiniposflag != 0 ? true : false;
                cb_tp_saveiniposflag.Checked = settings.ChannelConfig.omplconfig_testpos.TestPoints[id].saveiniposflag != 0 ? true : false;
            }

        }
<<<<<<< HEAD
=======
        private void SetConfigForm()
        {
            //振动通道配置
            listBox1.Items.Clear();
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                listBox1.Items.Add(name);
            }
            listBox1.SelectedIndex = 0;

            //转速通道配置
            listBox2.Items.Clear();
            count = settings.ChannelConfig.omplconfig_rotationchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].ChannelName;
                listBox2.Items.Add(name);
            }
            listBox2.SelectedIndex = 0;

            InitialTestPoints();
            InitialStorageInfo();

        }
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void InitialTestPoints()
        {
            listBox3.Items.Clear();
            int count = settings.ChannelConfig.omplconfig_testpos.TestPoints.Count;
            for (int i = 0; i < count; i++)
            {
                string name = settings.ChannelConfig.omplconfig_testpos.TestPoints[i].TestPointName;
                listBox3.Items.Add(name);
            }
            listBox3.SelectedIndex = 0;
        }
<<<<<<< HEAD

        //进度条
        private void ProgressBar(int t)
        {
            // 子线程解析进度条
            progressBar1.Maximum = 100;
            //控件清0
            progressBar1.Value = 0;
            //创建线程
            Thread th = new Thread(() => {

                for (int i = 1; i < 100; i++)
                {
                    if (i == 99)
                    {
                        Thread.Sleep(t);
                        progressBar1.BeginInvoke(
                            new Action<int>((c) =>
                            {
                                progressBar1.Value = 0;
                            }), 0);

                    }
                    else
                    {
                        //暂停当前线程
                        Thread.Sleep(t);
                        progressBar1.BeginInvoke(
                            new Action<int>((c) =>
                            {
                                progressBar1.Value = i;
                            }), i);
                    }
                }

            });
            //设置线程为背景线程
            th.IsBackground = true;
            th.Start();
        }
       

    }
}
=======
        private void InitialStorageInfo()
        {
            omplconfig_store storeSet = settings.StoreSet;
            UpdateStorage();
        }
        private void UpdateStorage()
        {
            cb_tp_nIndexHour.SelectedIndex = settings.StoreSet.HourInterval;
            cb_tp_nIndexDay.SelectedIndex = settings.StoreSet.DayInterval;
            cb_tp_nIndexWeek.SelectedIndex = settings.StoreSet.WeekInterval;
            cb_tp_nIndexMonth.SelectedIndex = settings.StoreSet.MonthInterval;
            cb_tp_nIndexYear.SelectedIndex = settings.StoreSet.YearInterval;
            tb_tp_strShengJiangSuBeg.Text = settings.StoreSet.LoadDB.ToString();
            tb_tp_strShengJiangSuEnd.Text = settings.StoreSet.StartSpeed.ToString();
            cb_tp_nIndexVariableloadDB.SelectedIndex = settings.StoreSet.Store;
            tb_tp_STRHeiXiaZiBeforeEvent.Text = settings.StoreSet.BlackBoxSavFre.ToString();
            tb_tp_strHeiXiaZiAfterEvent.Text = settings.StoreSet.BlackboxBeforeEvent.ToString();

        }

        private void SetDataGridForm()
        {
            //初始化位移列表
            dataGridView1.Columns.Add("id", "通道ID");//前面和相应名称相对于，后面显示在界面上可以随意改
            dataGridView1.Columns.Add("name", "通道名称");
            dataGridView1.Columns.Add("rpm", "转速");
            dataGridView1.Columns.Add("p2p", "峰峰值");
            dataGridView1.Columns.Add("gapvoltage", "间隙电压");
            dataGridView1.Columns.Add("rms", "平方根值");
            dataGridView1.Columns.Add("1xA", "一倍频幅值");
            dataGridView1.Columns.Add("1xP", "一倍频相位");
            dataGridView1.Columns.Add("2xA", "二倍频幅值");
            dataGridView1.Columns.Add("2xP", "二倍频相位");
            dataGridView1.Columns.Add("halfxA", "半频幅值");
            dataGridView1.Columns.Add("halfxP", "半频相位");
            dataGridView1.Rows.Add(32);//新增多少行，只能多不能少

            //初始化振动加速度列表
            dataGridView2.Columns.Add("id", "通道ID");
            dataGridView2.Columns.Add("name", "通道名称");
            dataGridView2.Columns.Add("rpm", "转速");
            dataGridView2.Columns.Add("TotalDB", "振动总值");
            dataGridView2.Columns.Add("highDB", "高频总值");
            dataGridView2.Columns.Add("lowDB", "低频总值");
            dataGridView2.Columns.Add("velocityRMS", "速度均方根值");
            dataGridView2.Columns.Add("AverageVol", "平均电压");
            dataGridView2.Columns.Add("displacementRMS", "位移均方根值");
            dataGridView2.Columns.Add("1xA", "一倍频幅值");
            dataGridView2.Columns.Add("2xA", "二倍频幅值");
            dataGridView2.Columns.Add("3xA", "三倍频幅值");
            dataGridView2.Rows.Add(32);


            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;

            for (int i = 0; i < count; i++)
            {
                int No = settings.ChannelConfig.Omaplchannels.Channels[i].No;
                string name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                if (i < DisplacementNo)//加载位移通道
                {
                    dataGridView1.Rows[i].Cells["id"].Value = No.ToString();
                    dataGridView1.Rows[i].Cells["name"].Value = name;
                }
                if (i>=(32- AccNo))//加载加速度通道
                {
                    dataGridView2.Rows[i - DisplacementNo].Cells["id"].Value = No.ToString();
                    dataGridView2.Rows[i - DisplacementNo].Cells["name"].Value = name;
                }

            }
        }
        //获总通道数量函数，在加载配置文件时调用，赋值给全局变量
        
     
        //获各类型通道数量函数，在加载配置文件时调用，赋值给全局变量
        
        private void GetChTypeNo()
        {
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            for (int i = 0; i < count; i++)
            {
                int type = settings.ChannelConfig.Omaplchannels.Channels[i].SensorType;
                if (type == 0)
                {
                    DisplacementNo++;//获取位移通道数量
                    //MessageBox.Show("位移");
                }
                if (type == 2)
                {
                    AccNo++;//获取加速度通道数量
                            // MessageBox.Show("加速度");
                }

            }

        }
        

        //连接硬件进度条时间
        private void Start1()
        {

            for (int i = 1; i < 100; i++)
            {
                if (i == 99)
                {
                    Thread.Sleep(30);
                    progressBar1.BeginInvoke(
                        new Action<int>((c) =>
                        {
                            progressBar1.Value = 0;
                        }), 0);

                }
                else
                {
                    //暂停当前线程
                    Thread.Sleep(30);
                    progressBar1.BeginInvoke(
                        new Action<int>((c) =>
                        {
                            progressBar1.Value = i;
                        }), i);
                }
            }

        }

        //下传配置进度条时间
        private void Start2()
        {

            for (int i = 1; i < 100; i++)
            {
                if (i == 99)
                {
                    Thread.Sleep(50);
                    progressBar1.BeginInvoke(
                        new Action<int>((c) =>
                        {
                            progressBar1.Value = 0;
                        }), 0);
                }
                else
                {
                    //暂停当前线程
                    Thread.Sleep(50);
                    progressBar1.BeginInvoke(
                        new Action<int>((c) =>
                        {
                            progressBar1.Value = i;
                        }), i);
                }
            }

        }
        //加载配置文件时间
        private void Start3()
        {

            for (int i = 1; i < 100; i++)
            {
                if (i == 99)
                {
                    Thread.Sleep(10);
                    progressBar1.BeginInvoke(
                        new Action<int>((c) =>
                        {
                            progressBar1.Value = 0;
                        }), 0);

                }
                else
                {
                    //暂停当前线程
                    Thread.Sleep(10);
                    progressBar1.BeginInvoke(
                        new Action<int>((c) =>
                        {
                            progressBar1.Value = i;
                        }), i);
                }
            }

        }

        private void UpdateGeneral(NetPacket packet)
        {
            int count = settings.ChannelConfig.Omaplchannels.Channels.Count;
            switch (packet.NetPacketHead.PacketType)
            {
                case PacketType.STRING:
                    //Console.WriteLine(packet.Data.ToString());
                    SetControlText(label39, packet.DataPacket.ToString());
                    break;
                //case PacketType.ACQParametersConfig:
                //    ACQParametersConfig acq = (ACQParametersConfig)packet.DataPacket;

                //    break;
                case PacketType.DisplacementPacket:
                    DisplacementData dpt = (DisplacementData)packet.DataPacket;
                    for (int i = 0; i < DisplacementNo; i++)
                    {
                        Control ctrl = tableLayoutPanel1.Controls[i];
                        string text = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName + "\r\n\r\n";
                        text += "峰峰值: " + dpt.CHDisData[i].PK2PK.ToString("0.0000") + "\r\n";
                        text += "间隙电压: " + dpt.CHDisData[i].GapVoltage.ToString("0.0000") + "\r\n";
                        //name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                        SetControlText(ctrl, text);
                        //更新位移通道数据列表
                        dataGridView1.Rows[i].Cells["p2p"].Value = dpt.CHDisData[i].PK2PK.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["gapvoltage"].Value = dpt.CHDisData[i].GapVoltage.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["rms"].Value = dpt.CHDisData[i].RoomSquareValue.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["p2p"].Value = dpt.CHDisData[i].PK2PK.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["1xA"].Value = dpt.CHDisData[i].OneMultiplierAmp.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["1xP"].Value = dpt.CHDisData[i].OneMultiplierPhase.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["2xA"].Value = dpt.CHDisData[i].TWOMultiplierAmp.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["2xP"].Value = dpt.CHDisData[i].TWOMultiplierPhase.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["halfxA"].Value = dpt.CHDisData[i].HalfMultiplierAmp.ToString("0.0000");
                        dataGridView1.Rows[i].Cells["halfxP"].Value = dpt.CHDisData[i].HaltMultiplierPhase.ToString("0.0000");

                    }
                    break;
                case PacketType.AccelerationPacket:
                    AccData acc = (AccData)packet.DataPacket;
                   
                    for (int i = DisplacementNo; i < count; i++)
                    {
                        Control ctrl = tableLayoutPanel1.Controls[i];//设置对应第一个控件
                        string text = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName + "\r\n\r\n";
                        text += "振动总值update: " + acc.CHAccData[i- DisplacementNo].TotalDB.ToString("0.0000") + "\r\n";
                        text += "平均电压: " + acc.CHAccData[i- DisplacementNo].AverageVol.ToString("0.0000") + "\r\n";
                        //name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                        // SetControlText(ctrl, text);
                        //更新加速度通道数据列表
                        dataGridView2.Rows.Clear();
                       
                        
                        dataGridView2.Rows[i - DisplacementNo].Cells["TotalDB"].Value = acc.CHAccData[i - DisplacementNo].TotalDB.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["highDB"].Value = acc.CHAccData[i - DisplacementNo].highDB.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["lowDB"].Value = acc.CHAccData[i - DisplacementNo].lowDB.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["velocityRMS"].Value = acc.CHAccData[i - DisplacementNo].velocityRMS.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["AverageVol"].Value = acc.CHAccData[i - DisplacementNo].AverageVol.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["displacementRMS"].Value = acc.CHAccData[i - DisplacementNo].displacementRMS.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["1xA"].Value = acc.CHAccData[i - DisplacementNo].OneMultiplierAmp.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["2xA"].Value = acc.CHAccData[i - DisplacementNo].TWOMultiplierAmp.ToString("0.0000");
                        dataGridView2.Rows[i - DisplacementNo].Cells["3xA"].Value = acc.CHAccData[i - DisplacementNo].HalfMultiplierAmp.ToString("0.0000");
                        
                    }
                    break;
                case PacketType.SpeedPacket:
                    SpeedData speed = (SpeedData)packet.DataPacket;
                    for (int i = 0; i < 6; i++)
                    {
                        Control ctrl = tableLayoutPanel1.Controls[i + 32];
                        string text = settings.ChannelConfig.omplconfig_rotationchannels.Channels[i].ChannelName + "\r\n\r\n";
                        text += "转速" + i.ToString() + speed.ChSpeeds[i].rpm.ToString("0.0") + "\r\n";
                        //name = settings.ChannelConfig.Omaplchannels.Channels[i].ChannelName;
                        SetControlText(ctrl, text);

                    }
                    for (int i = 0; i < count; i++)
                    {   //更新位移数据列表转速项
                        if (i < DisplacementNo)
                        {
                            dataGridView1.Rows[i].Cells["rpm"].Value = speed.ChSpeeds[i].rpm.ToString("0.0");
                        }
                        //更新加速度数据列表转速项
                        dataGridView2.Rows[i- DisplacementNo].Cells["rpm"].Value = speed.ChSpeeds[i].rpm.ToString("0.0");
                    }
                    break;
                case PacketType.SpeedVoltagePacket:
                    SpeedRealTVol speedVol = (SpeedRealTVol)packet.DataPacket;

                    break;
                default:
                    break;
            }
        }

        private void SetControlText(Control ctrl, string name)
        {
            if (ctrl.IsHandleCreated && ctrl.InvokeRequired)
            {
                ctrl.Invoke(new Action<Control, string>(SetControlText), ctrl, name);
                return;
            }
            ctrl.Text = name;
        }

        
        private void SetLabelContentAcc(Label label, string name, int alarmFlag,int index,float TotalDB,float highDB,float lowDB,int i,AccData acc)
        {
           
            if (label.IsHandleCreated && label.InvokeRequired)
            {
                label.Invoke(new Action<Label, string, int,int,float,float,float,int,AccData>(SetLabelContentAcc), label, name, alarmFlag);
                return;
            }

            //读取配置文件储存对应通道的使能信息，如果勾选则根据报警位改变颜色
            if (settings.ChannelConfig.Omaplchannels.Channels[index].FlagIsUser  != 0)
            {
               // MessageBox.Show("启动标志位报警");
                switch (alarmFlag)
                {
                    case 0: label.BackColor = Color.Green; break;

                    case 1: label.BackColor = Color.Yellow; break;

                    case 2: label.BackColor = Color.Red; break;
                }
            }
            //振动加速度总值报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeValueIsUser != 0)
            {
              //  MessageBox.Show("启动振动加速度总值报警");
                if (TotalDB < settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeYellowValue)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeYellowValue <= TotalDB && TotalDB < settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeRedValue)
                { label.BackColor = Color.Yellow; }


                else if
                    (TotalDB >= settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeRedValue)
                { label.BackColor = Color.Red; }
            }
            //高频段阈值报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeValueIsUser != 0)
            {
            //    MessageBox.Show("启用高频段阈值报警");
                if (highDB < settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeYellowValue)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeYellowValue <= highDB && highDB < settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeRedValue)
                { label.BackColor = Color.Yellow; }

                else if
                    (highDB >= settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeRedValue)
                { label.BackColor = Color.Red; }
            }
            //低频段阈值报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeValueIsUser != 0)
            {
              //  MessageBox.Show("启用低频段阈值报警");
                if (lowDB < settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeYellowValue)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeYellowValue <= lowDB && lowDB < settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeRedValue)
                { label.BackColor = Color.Yellow; }


            else if
                (lowDB >= settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeRedValue)
                { label.BackColor = Color.Red; }
            }
            //如果不设置报警则为白色
            if (settings.ChannelConfig.Omaplchannels.Channels[index].FlagIsUser == 0 && settings.ChannelConfig.Omaplchannels.Channels[index].AccTotalAmplitudeValueIsUser == 0 &&
                settings.ChannelConfig.Omaplchannels.Channels[index].AccHighAmplitudeValueIsUser == 0 && settings.ChannelConfig.Omaplchannels.Channels[index].AccLowAmplitudeValueIsUser == 0)
            { label.BackColor = Color.White; }
            label.Text = name;


            //更新加速度数据列表
            
            //MessageBox.Show("更新列表");
            dataGridView2.Rows[i - DisplacementNo].Cells["TotalDB"].Value = acc.CHAccData[i - DisplacementNo].TotalDB.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["highDB"].Value = acc.CHAccData[i - DisplacementNo].highDB.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["lowDB"].Value = acc.CHAccData[i - DisplacementNo].lowDB.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["velocityRMS"].Value = acc.CHAccData[i - DisplacementNo].velocityRMS.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["AverageVol"].Value = acc.CHAccData[i - DisplacementNo].AverageVol.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["displacementRMS"].Value = acc.CHAccData[i - DisplacementNo].displacementRMS.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["1xA"].Value = acc.CHAccData[i - DisplacementNo].OneMultiplierAmp.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["2xA"].Value = acc.CHAccData[i - DisplacementNo].TWOMultiplierAmp.ToString("0.0000");
            dataGridView2.Rows[i - DisplacementNo].Cells["3xA"].Value = acc.CHAccData[i - DisplacementNo].HalfMultiplierAmp.ToString("0.0000");
            dataGridView2.RefreshEdit();



        }
        private void SetLabelContentDis(Label label, string name, int alarmFlag, int index, float RoomSquareValue ,float OneMultiplierAmp, float TWOMultiplierAmp, float HalfMultiplierAmp)
        {
            if (label.IsHandleCreated && label.InvokeRequired)
            {
                label.Invoke(new Action<Label, string, int, int,float, float, float, float>(SetLabelContentDis), label, name, alarmFlag);
                return;
            }
            //读取配置文件储存对应通道的使能信息，如果勾选则根据报警位改变颜色
            if (settings.ChannelConfig.Omaplchannels.Channels[index].FlagIsUser != 0)
            {
                switch (alarmFlag)
                {
                    case 0: label.BackColor = Color.Green; break;

                    case 1: label.BackColor = Color.Yellow; break;

                    case 2: label.BackColor = Color.Red; break;
                }
            }
            //通频阈值报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].Enable != 0)
            {
                if (RoomSquareValue < settings.ChannelConfig.Omaplchannels.Channels[index].Warning)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].Warning <= RoomSquareValue && RoomSquareValue < settings.ChannelConfig.Omaplchannels.Channels[index].Alarm)
                { label.BackColor = Color.Yellow; };
            }
            else if
                (RoomSquareValue >= settings.ChannelConfig.Omaplchannels.Channels[index].Alarm)
            { label.BackColor = Color.Red; }

            //一倍频报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Enable != 0)
            {
                if (OneMultiplierAmp < settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Warning)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Warning <= OneMultiplierAmp && OneMultiplierAmp < settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Alarm)
                { label.BackColor = Color.Yellow; };
            }
            else if
                (OneMultiplierAmp >= settings.ChannelConfig.Omaplchannels.Channels[index].Frequency1Alarm)
            { label.BackColor = Color.Red; }

            //二倍频报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Enable != 0)
            {
                if (TWOMultiplierAmp < settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Warning)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Warning <= TWOMultiplierAmp && TWOMultiplierAmp < settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Alarm)
                { label.BackColor = Color.Yellow; };
            }
            else if
                (TWOMultiplierAmp >= settings.ChannelConfig.Omaplchannels.Channels[index].Frequency2Alarm)
            { label.BackColor = Color.Red; }

            //半倍频报警
            if (settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfEnable != 0)
            {
                if (HalfMultiplierAmp < settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfWarning)
                {
                    label.BackColor = Color.Green;
                }
                else if
                    (settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfWarning <= HalfMultiplierAmp && HalfMultiplierAmp < settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfAlarm)
                { label.BackColor = Color.Yellow; };
            }
            else if
                (HalfMultiplierAmp >= settings.ChannelConfig.Omaplchannels.Channels[index].FrequencyHalfAlarm)
            { label.BackColor = Color.Red; }

            label.Text = name;

        }

        private void SetComboIndex(ComboBox ctrl, int index)
        {
            if (ctrl.IsHandleCreated && ctrl.InvokeRequired)
            {
                ctrl.Invoke(new Action<ComboBox, int>(SetComboIndex), ctrl, index);
                return;
            }
            if (index >= 0)
                ctrl.SelectedIndex = index;
        }

    }

}


>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
